<?php

/* Control showing error */
if (DEBUG)
{
    error_reporting(E_ALL);
}
else
{
    error_reporting(0);
}

try
{
    // Loader
    $corePath = SYSTEM_PATH . 'core/';
    require($corePath . 'Loader.php');

    /* Load class */
    Loader::loadFile($corePath . 'Config.php');
    Loader::loadFile($corePath . 'Router.php');
    Loader::loadFile($corePath . 'FrontController.php');
    Loader::loadFile($corePath . 'Controller.php');
    Loader::loadFile($corePath . 'Model.php');
    Loader::loadFile($corePath . 'Template.php');
    Loader::loadFile($corePath . 'Response.php');
    Loader::loadFile($corePath . 'MyException.php');
    
    /* Application */
    Config::load(APPLICATION_PATH . 'config.php');

    $router = Router::create();
    $frontController = new FrontController($router);

    $response = $frontController->dispatch();

    Loader::getInstance()->unload();

    $response->sendHeaders();
    $response->output();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}
?>